<template>
	<view class="classify-box" @touchmove.stop.prevent="moveHandle">
		<view class="classify-disalog">
			<view class="disalog-title">
				 标签
			</view>
			<view class="disalog-content">
				<view class="tag-item" :class="{'selected' : selectedindex == index}" @click="radioChange(index)" :key="item.id" v-for="(item,index) in tagList">{{item.name}}</view>
			</view>
			<view class="button-box" @click="cancel">
				<view class="button cancel-button">
					取消
				</view>
				<view @click="confirm" class="button confirm-button">
					确定
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			selected:{
				type:Number,
				default:null
			},
			value:{
				type:String,
				default:''
			},
		},
		data() {
			return {
				selectedindex:null,
				tagList:[
					{
						id:1,
						name:'安全',
					},
					{
						id:2,
						name:'质量',
					},
					{
						id:3,
						name:'采购',
					},
					{
						id:4,
						name:'设计',
					},
					{
						id:5,
						name:'研发',
					},
					{
						id:6,
						name:'生产',
					},
					{
						id:7,
						name:'仓库',
					},
					{
						id:8,
						name:'设备',
					},
					{
						id:9,
						name:'销售',
					},
					{
						id:10,
						name:'市场',
					},
					{
						id:11,
						name:'人事',
					},
					{
						id:12,
						name:'行政',
					},
					{
						id:13,
						name:'财务',
					},
					{
						id:14,
						name:'信息',
					},
					{
						id:15,
						name:'税务',
					},
					{
						id:16,
						name:'法律',
					},
					{
						id:17,
						name:'其他',
					},
				],
			}
		},
		created() {
			let tagList = this.tagList;
			let value = this.value;
			if(value != ''){
				let data = tagList.filter(res=>{
					return res.name == value;
				})
				if(data.length > 0){
					this.selectedindex = data[0].id - 1;
				}
			}else{
				this.selectedindex = this.selected;
			}
			
		},
		methods: {
			radioChange:function(index){
				this.selectedindex = index;
				// this.$emit('change',index);
			},
			cancel:function(){
				this.$emit('cancel');
			},
			confirm:function(){
				let index = this.selectedindex;
				this.$emit('confirm',{index:index,result:this.tagList[index]});
			},
			 moveHandle(){
					return
				},
		}
	}
</script>

<style lang="scss" scoped>
	.classify-box{
		position: fixed;
		width: 100%;
		height: 100vh;
		top: 0;
		left: 0;
		background: rgba(20,20,20,0.5);
	}
	.classify-disalog{
		background-color: white;
		border-radius: 10rpx;
		margin: 0 auto;
		position: relative;
		top: 20%;
		animation-name: disalogshow;
		animation-duration:0.5s;
		width:calc(100% - 180rpx);
		box-sizing: border-box;
		padding: 20rpx;
		.disalog-title{
			text-align: center;
		}
		.disalog-content{
			margin-top: 30rpx;
			display: flex;
			flex-wrap: wrap;
			.tag-item{
				border:1px solid #ebebeb;
				border-radius: 10rpx;
				padding:0 50rpx;
				font-size: 28rpx;
				line-height:70rpx;
				margin-left: 20rpx;
				margin-bottom: 20rpx;
				white-space: nowrap;
			}
			
			.tag-item:nth-child(3n + 1){
				margin-left: 0;
			}
			.selected{
				background-color: #36af86;
				color: white;
			}
			
		}
		.button-box{
			display: flex;
			margin-top: 30rpx;
			justify-content: space-around;
			.button{
				width:calc(50% - 20rpx);
				line-height:70rpx;
				text-align: center;
				color: white;
				border-radius: 10rpx;
			}
			.cancel-button{
				background-color: #888888;
			}
			.confirm-button{
				background-color: #36af86;
			}
		}
	}
	@keyframes disalogshow
	{
	    0%   {
			transform:scale(0);
			opacity: 0;
			}
	    100% {
			transform:scale(1);
			opacity: 1;
			}
	}
</style>
